package com.sixbing.demo.base;

import android.content.Context;

import com.sixbing.demo.utils.NetUtils;
import com.hjq.toast.ToastUtils;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableObserver;


/**
 * Created by xiangl
 * on 2018/4/24 0024 下午 2:53
 * description :
 */
public class BasePresenter<V extends BaseViewI> implements BasePresenterI {
    private String TAG = this.getClass().getSimpleName();
    public V mView;
    private Context mContext;
    private CompositeDisposable mCompositeDisposable;

    @Override
    public boolean checkNetWork(Context context) {
        if (!NetUtils.checkNetWork(context)) {
            ToastUtils.show("网络不可用，请检查网络");
        }
        return NetUtils.checkNetWork(context);
    }


    public void attachView(V view, Context context) {
        this.mView = view;
        this.mContext = context;
    }


    /**
     * 事件订阅
     */
    protected void addCompositeDisposable(DisposableObserver observable) {
        if (mCompositeDisposable == null) {
            mCompositeDisposable = new CompositeDisposable();
        }
        mCompositeDisposable.add(observable);
    }


    @Override
    public void unSubcrible() {
        if (this.mCompositeDisposable != null) {
            this.mCompositeDisposable.dispose();
        }
        mView = null;
        mContext = null;
    }
}
